package com.flc.gateway.utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


/**
 * PropertyFactory
 * 
 * @author xlj
 * 
 */
public class PropertyFactory {
	
	private Properties properties;


	/**
	 * 初始化PropertyFactory类
	 */
	public PropertyFactory(String filePath) {
		loadProperties(filePath);
	}
	
	private void loadProperties(String filePath) {
		properties = new Properties();
		try {
			FileInputStream inputFile = new FileInputStream(filePath);
			properties.load(inputFile);
			inputFile.close();
		} catch (FileNotFoundException ex) {
			try {
				InputStream inStr = ClassLoader.getSystemResourceAsStream(filePath);
				properties.load(inStr);
				inStr.close();
			} catch (IOException e) {
				System.out.println("NoFileFound:"+filePath);
				e.printStackTrace();
			}
		} catch (IOException ex) {
			System.out.println("装载文件失败:"+filePath);
			ex.printStackTrace();
		}
	}

	/**
	 * 获取key值
	 */
	public String getValue(String key) {
		if (properties.containsKey(key)) {
			return properties.getProperty(key);
		} else{
			return "";
		}
	}
}
